package com.hollycrm.hollysqm.core.waveform.wordcloud;

/**
 * 像素使用与否索引类
 */
public class PlotMap {
	public PlotMap(int w, int h) {
		if (w <= 0 || h <= 0)
			throw new IllegalArgumentException();
		width = w+100;
		height = h+100;
		bitMap = new byte[width][height];
		for (int x = 0; x < width; x++)
			for (int y = 0; y < height; y++)
				bitMap[x][y] = 0;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}





	public boolean isUsed(int x, int y) {
	
		return bitMap[x][y]>0;
	}

	public void setUsed(int x, int y) {
		
		bitMap[x][y]=1;
	}

	public void debug() {
		System.out.println((new StringBuilder("=== DEBUG ( ")).append(width)
				.append(" x ").append(height).append(" ) ===").toString());
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				boolean used = isUsed(x, y);
				System.out.print(used ? "*" : ".");
			}
			System.out.println();
		}
	}

	private byte bitMap[][];
	private int width;
	private int height;
}
